//扑克牌大小

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


string checkWin(const string& s)
{
    if(s.find("joker JOKER") != string::npos) return "joker JOKER";
    //拆分左右手的牌
    int index = s.find('-');
    string left(s.begin(), s.begin()+index);
    string right(s.begin()+index+1, s.end());
    //左右手牌数目
    int lnum = count(left.begin(), left.end(), '-') + 1;//字符被-拆开，因此是'-'数目+1
    int rnum = count(right.begin(), right.end(), '-') + 1;
    //取左右手第一张牌
    string left_first(left.begin(), left.begin()+left.find(' '));
    string right_first(right.begin(), right.begin()+right.find(' '));
    //同类型比较
    if(lnum == rnum)
    {
        string tmp = "345678910JQKAjokerJOKER";
        if(tmp.find(left_first) > tmp.find(right_first)) return left;
        else return right;
    }
    //不为同类型，可能是炸弹
    if(4 == lnum) return left;
    else if(4 == rnum) return right;

    return "ERROR";
}
int main()
{
    string s;
    getline(cin, s);

    cout << checkWin(s) << endl;

    return 0;
}